// 已知在一维数组A[m + n]中依次存放两个线性表(a1, a2, a... am)和(b1, b2, b..,bn).试编
// 写一个函数，将数组中两个顺序表的位置互换，即将(b], b2, b3,", b,)放在(a, a2, a,",amn)
// 的前面。

#pragma once

#define m 100
#define n 20
#include "iostream"

int A[m + n];
void initA()
{
    for (int i = 0; i < m + n; i++)
    {
        A[i] = i;
    }
}
void consoleA()
{
    for (int i = 0; i < m + n; i++)
    {
        std::cout << A[i] << ",";
    }
    std::cout << std::endl;
}
void reverseInRange(int *A, int begin, int end)
{
    for (int i = 0; i < (end - begin) / 2; i++)
    {
        // std::cout << "before " << A[begin + i] << "," << A[end - i] << "\r\n";
        int temp = A[begin + i];
        A[begin + i] = A[end - i];
        A[end - i] = temp;
        // std::cout << "after " << A[begin + i] << "," << A[end - i] << "\r\n";
    }
    // consoleA();
}
int main()
{
    initA();
    reverseInRange(A, 0, m + n - 1);
    reverseInRange(A, 0, n - 1);
    reverseInRange(A, n, m + n - 1);
    consoleA();
    return 0;
}